home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-09-17 | 9.6 KB | 356 lines | [TEXT/MPS ] |
- //========================================================================================
- //
- // File: FWGXUtil.cpp
- // Release Version: $ ODF 2 $
- //
- // Copyright: (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
- //
- //========================================================================================
-
- #include "FWOS.hpp"
-
- #ifndef FWGXCFG_H
- #include "FWGXCfg.h"
- #endif
-
- #ifdef FW_SUPPORT_GX
-
- #ifndef FWGXUTIL_H
- #include "FWGXUtil.h"
- #endif
-
- #ifndef FWACQUIR_H
- #include "FWAcquir.h"
- #endif
-
- #ifndef FWDEBUG_H
- #include "FWDebug.h"
- #endif
-
- #ifndef FWPOINT_H
- #include "FWPoint.h"
- #endif
-
- #ifndef FWRECT_H
- #include "FWRect.h"
- #endif
-
- // ----- Platform includes
-
- #ifndef __GESTALT__
- #include <Gestalt.h>
- #endif
-
- #ifndef __GXGRAPHICS__
- #include <GXGraphics.h>
- #endif
-
- #ifndef __GXPRINTING__
- #include <GXPrinting.h>
- #endif
-
- // ----- OpenDoc includes
-
- #ifndef SOM_ODFrame_xh
- #include <Frame.xh>
- #endif
-
- #ifndef SOM_ODFacet_xh
- #include <Facet.xh>
- #endif
-
- #ifndef SOM_ODCanvas_xh
- #include <Canvas.xh>
- #endif
-
- #ifndef SOM_ODShape_xh
- #include <Shape.xh>
- #endif
-
- // ------ Standard includes
-
- // #include <string.h>
-
- //----------------------------------------------------------------------------------------
-
- #ifdef FW_BUILD_MAC
- #pragma segment FW_GXUtilities
- #endif
-
- //----------------------------------------------------------------------------------------
- // FW_IsGXInstalled
- //----------------------------------------------------------------------------------------
-
- FW_Boolean FW_IsGXInstalled()
- {
- static FW_Boolean gAlreadyChecked = FALSE, gAnswer = FALSE;
-
- // since this may be called repeatedly, check Gestalt only
- // once and cache the answer. We'll assume for now that GX
- // doesn't go on an off line during a single session.
- if (!gAlreadyChecked) // have we already checked Gestalt?
- {
- ODSLong version;
-
- // go and check Gestalt
- gAlreadyChecked = true;
- gAnswer = (Gestalt(gestaltGraphicsVersion, &version) == noErr);
-
- // To be sure that the code fragment is here
- if (gAnswer)
- gAnswer = ((void*)::GXEnterGraphics != (void*)kUnresolvedCFragSymbolAddress);
- }
-
- return gAnswer;
- }
-
- //----------------------------------------------------------------------------------------
- // FW_GX_Initialize
- //----------------------------------------------------------------------------------------
-
- void FW_Priv_GX_Initialize()
- {
- if (FW_IsGXInstalled())
- {
- ::GXEnterGraphics();
- ::GXInitPrinting();
- }
- }
-
- //----------------------------------------------------------------------------------------
- // FW_GX_Terminate
- //----------------------------------------------------------------------------------------
-
- void FW_Priv_GX_Terminate()
- {
- if (FW_IsGXInstalled())
- {
- ::GXExitPrinting();
- ::GXExitGraphics();
- }
- }
-
- //========================================================================================
- // class FW_CGraphicContextGX
- //========================================================================================
-
- FW_DEFINE_AUTO(FW_CGraphicContextGX)
-
- //----------------------------------------------------------------------------------------
- // FW_CGraphicContextGX::FW_CGraphicContextGX
- //----------------------------------------------------------------------------------------
-
- FW_CGraphicContextGX::FW_CGraphicContextGX(
- Environment* ev,
- ODFacet* facet,
- ODShape* invalidShape)
- {
- FW_REQUIRE(FW_IsGXInstalled());
-
- ODCanvas* canvas = facet->GetCanvas(ev);
-
- // ----- Get / create the GX objects that we will need
- fGXTransform = ::GXNewTransform();
- fGXViewPort = (gxViewPort) canvas->GetGXViewport(ev);
-
- // ----- Set up transform mapping
- SetupTransformMapping(ev, facet);
-
- // ----- Set up viewport clipping
- SetupViewPortClipping(ev, facet, invalidShape);
-
- // ----- Set up transform clipping
- SetupTransformClipping(ev, facet);
-
- // ----- Plug the viewport into the frame's transform
- ::GXSetTransformViewPorts(fGXTransform, 1, &fGXViewPort);
-
- FW_END_CONSTRUCTOR
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CGraphicContextGX::~FW_CGraphicContextGX
- //----------------------------------------------------------------------------------------
-
- FW_CGraphicContextGX::~FW_CGraphicContextGX()
- {
- FW_START_DESTRUCTOR
-
- ::GXSetTransformViewPorts(fGXTransform, 0, NULL);
-
- RestoreTransformClipping();
-
- RestoreViewPortClipping();
-
- RestoreTransformMapping();
-
- ::GXDisposeTransform(fGXTransform);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CGraphicContextGX::SetupTransformMapping
- //----------------------------------------------------------------------------------------
-
- void FW_CGraphicContextGX::SetupTransformMapping(
- Environment* ev,
- ODFacet* facet)
- {
- ODCanvas* canvas = facet->GetCanvas(ev);
- FW_CAcquiredODTransform aqFacetXForm = facet->AcquireFrameTransform(ev, canvas);
-
- aqFacetXForm->GetMatrix(ev, (ODMatrix*) &fMapping);
-
- ::GXGetTransformMapping(fGXTransform, &fOldMapping);
-
- ::MapMapping(&fMapping, &fOldMapping);
- ::GXSetTransformMapping(fGXTransform, &fMapping);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CGraphicContextGX::RestoreTransformMapping
- //----------------------------------------------------------------------------------------
-
- void FW_CGraphicContextGX::RestoreTransformMapping()
- {
- ::GXSetTransformMapping(fGXTransform, &fOldMapping);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CGraphicContextGX::SetupTransformClipping
- //----------------------------------------------------------------------------------------
-
- void FW_CGraphicContextGX::SetupTransformClipping(
- Environment* ev,
- ODFacet* facet)
- {
- gxShape transformClip = NULL;
-
- ODFrame* frame = facet->GetFrame(ev);
- ODCanvas* canvas = facet->GetCanvas(ev);
-
- if (canvas->HasPlatformPrintJob(ev, kODQuickDrawGX))
- {
- // Printing
- FW_CPoint extent;
- frame->GetContentExtent(ev, (ODPoint*)&extent);
-
- FW_CRect extentRect(FW_kZeroPoint, extent);
- transformClip = GXNewRectangle((gxRectangle*)&extentRect);
- }
- else
- {
- // Drawing to the screen
- FW_CAcquiredODShape aqFrameShape = frame->AcquireFrameShape(ev, NULL);
- transformClip = aqFrameShape->GetGXShape(ev);
- }
-
- fTransformClipOld = ::GXGetTransformClip(fGXTransform);
- ::GXSetTransformClip(fGXTransform, transformClip);
-
- #ifdef FW_DEBUG
- gxRectangle boundsTransformClip;
- ::GXGetShapeBounds(transformClip, 0, &boundsTransformClip);
-
- gxRectangle boundsTransformClipOld;
- ::GXGetShapeBounds(fTransformClipOld, 0, &boundsTransformClipOld);
- #endif
-
- ::GXDisposeShape(transformClip);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CGraphicContextGX::RestoreTransformClipping
- //----------------------------------------------------------------------------------------
-
- void FW_CGraphicContextGX::RestoreTransformClipping()
- {
- ::GXSetTransformClip(fGXTransform, fTransformClipOld);
- ::GXDisposeShape(fTransformClipOld);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CGraphicContextGX::SetupViewPortClipping
- //----------------------------------------------------------------------------------------
-
- void FW_CGraphicContextGX::SetupViewPortClipping(
- Environment* ev,
- ODFacet* facet,
- ODShape* invalidShape)
- {
- ODCanvas* canvas = facet->GetCanvas(ev);
- FW_CAcquiredODShape aqFacetClipShape = facet->AcquireAggregateClipShape(ev, canvas);
-
- #ifdef FW_DEBUG
- FW_CRect boundsFacetClipShape;
- aqFacetClipShape->GetBoundingBox(ev, (ODRect*) &boundsFacetClipShape);
- #endif
-
- // ----- Map the clip shape's copy back to local coordinates
- gxShape facetGXShape = aqFacetClipShape->GetGXShape(ev);
- gxShape viewPortClip = ::GXCopyToShape(NULL, facetGXShape);
- ::GXDisposeShape(facetGXShape);
-
- ::GXSetShapeAttributes(viewPortClip, GXGetShapeAttributes(viewPortClip) & ~gxMapTransformShape);
- // ::GXMapShape(viewPortClip, &fMapping);
-
- // ----- Intersect the clip shape with the invalid shape
- if (invalidShape != NULL)
- {
- gxShape invalidGXShape = invalidShape->GetGXShape(ev);
- ::GXIntersectShape(viewPortClip, invalidGXShape);
- ::GXDisposeShape(invalidGXShape);
- }
-
- // [HLX] move here because of bug #1306478
- ::GXMapShape(viewPortClip, &fMapping);
-
- // ----- Save the current clip and set the new old
- fViewPortClipOld = ::GXGetViewPortClip(fGXViewPort);
-
- #ifdef FW_DEBUG
- gxRectangle boundsViewPortClip;
- ::GXGetShapeBounds(viewPortClip, 0, &boundsViewPortClip);
-
- gxRectangle boundsViewPortClipOld;
- ::GXGetShapeBounds(fViewPortClipOld, 0, &boundsViewPortClipOld);
- #endif
-
- ::GXSetViewPortClip(fGXViewPort, viewPortClip);
- ::GXDisposeShape(viewPortClip);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CGraphicContextGX::RestoreViewPortClipping
- //----------------------------------------------------------------------------------------
-
- void FW_CGraphicContextGX::RestoreViewPortClipping()
- {
- ::GXSetViewPortClip(fGXViewPort, fViewPortClipOld);
- ::GXDisposeShape(fViewPortClipOld);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CGraphicContextGX::DrawShape
- //----------------------------------------------------------------------------------------
-
- void FW_CGraphicContextGX::DrawShape(gxShape shape)
- {
- gxTransform oldTransform = ::GXGetShapeTransform(shape);
- ::GXSetShapeTransform(shape, fGXTransform);
-
- ::GXDrawShape(shape);
-
- ::GXSetShapeTransform(shape, oldTransform);
- }
-
- //----------------------------------------------------------------------------------------
- // FW_CGraphicContextGX::GetGXTransform
- //----------------------------------------------------------------------------------------
-
- gxTransform FW_CGraphicContextGX::GetGXTransform() const
- {
- return fGXTransform;
- }
-
- #endif // FW_SUPPORT_GX
-